<?
/*! \brief Manages all services within OpenBT
 * 
 */
class ServiceManager
{
	private $_serviceList;
	
	public function __construct() {}
	
	public static function getServices()
	{
		$services = ServiceManager::readDirectory(
			ServiceManager::getServiceDir());
		$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
		$xml = $xml.'<services>';
		for($i=0; $i<count($services); $i++)
			$xml = $xml.'<service>'.$services[$i].'</service>';
		$xml = $xml.'</services>';
		return $xml;
	}
	
	public static function readDirectory($dir)
	{
		$directory = opendir($dir);
		
		while($file = readdir($directory))
		{
			if(!ereg("^\.", $file))
				$dirArray[] = preg_replace("/.xml/", "", $file);
		}
		
		closedir($directory);
		return $dirArray;
	}
	
	public static function getServiceDir()
	{
		return BASE_DIR.'/public/services/';
	}
	
	public static function isService($method=null)
	{
		return file_exists(ServiceManager::getServiceDir().$method.'.xml');
	}
	
	public static function getServiceXml($service)
	{
		$file = ServiceManager::getServiceDir().$service.'xml';
		return file_get_contents($file);	
	}
}
